// pages/classify/classify.js
Page({
    data: {
      baseURL: 'http://43.139.97.111:8080',
      children:[],
      ishaveChild:true,
      cateItems: [],
      curNav: '',
      curIndex: 0,
      firstTypeId:''
    },
    onLoad(options) {
      var _this=this;
      var bookTypeId = '';
      wx.showLoading({
        title: '加载中',
        mask:true
      })
      wx.request({
        url: 'http://43.139.97.111:8080/bookType/queryAll',
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          console.log(res.data);
          if(res.statusCode==200){
            _this.setData({
              cateItems:res.data.data
            })
          }
        }
      })
      wx.request({
        url: 'http://43.139.97.111:8080/books/queryByType?bookTypeId=24',
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          console.log(res.data);
          if(res.statusCode==200){
            _this.setData({
              children:res.data.data,
              curNav:24
            })
          }
          wx.hideLoading()
        }
      })
    },
  
    //事件处理函数  
    switchRightTab: function (e) {
      // 获取item项的id，和数组的下标值  
      let id = e.target.dataset.id,
        index = parseInt(e.target.dataset.index)+1;
      // 把点击到的某一项，设为当前index
      this.setData({
        curNav: id,
        curIndex: index
      })
      console.log(id);
      var _this=this;
      wx.showLoading({
        title: '加载中',
        mask:true
      })
      wx.request({
        url: 'http://43.139.97.111:8080/books/queryByType?bookTypeId='+id,
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          console.log(res.data);
          if(res.statusCode==200&&res.data.data!=''){
            _this.setData({
              children:res.data.data,
              ishaveChild:true
            })
          }else{
            _this.setData({
              ishaveChild:false
            })
          }
          if(_this.data.children==''){
              _this.data.ishaveChild=false
          }
          wx.hideLoading()
        }
      })
    },
    search:function(e){
      wx.navigateTo({
        url: '/pages/search/search',
      })
    },
    booklist:function(e){
      var _this=this;
      console.log(_this.data.children);
      wx.navigateTo({
        url: '/pages/moreList/moreList?booklist='+JSON.stringify(_this.data.children),
      })
    },
  })  